package com.example.dllo.exe.fenlei.gonglue;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.exe.BuildConfig;
import com.example.dllo.exe.R;
import com.example.dllo.exe.bean.DanPinPinJieDownBean;
import com.example.dllo.exe.fengzhuang.NetTool;
import com.example.dllo.exe.fenlei.danpin.DanPinPinJieAdapter;

/**
 * code is far away from bug with the animal protecting
 * <p/>
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃永无BUG！  凯哥 祝你一路顺风
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 */
public class DanPinPinJieDownAdapter extends BaseAdapter {
    private Context context;
    private DanPinPinJieDownBean bean;


    public void setBean(DanPinPinJieDownBean bean) {
        this.bean = bean;

        notifyDataSetChanged();
    }

    public DanPinPinJieDownAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        int count = bean != null ? bean.getData().getPosts().size() : 0;

        return bean != null ? bean.getData().getPosts().size() : 0;

    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        LayoutInflater inflater = LayoutInflater.from(context);
        if (view == null) {
            view = inflater.inflate(R.layout.danpinpinjiedownlayout, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.texttitle.setText(bean.getData().getPosts().get(i).getTitle());
        viewHolder.textlikecounts.setText(bean.getData().getPosts().get(i).getLikes_count() + "");
        viewHolder.textnickname.setText(bean.getData().getPosts().get(i).getAuthor().getNickname());


        NetTool netTool = new NetTool();
        netTool.getImage(bean.getData().getPosts().get(i).getCover_image_url(), viewHolder.imagecoverimageurl);
        return view;
    }

    public class ViewHolder {
        TextView texttitle;
        ImageView imagecoverimageurl;
        TextView textnickname;
        TextView textlikecounts;

        public ViewHolder(View view) {
            texttitle = (TextView) view.findViewById(R.id.text_title);
            textnickname = (TextView) view.findViewById(R.id.text_nick_name);
            textlikecounts = (TextView) view.findViewById(R.id.text_likecounts);
            imagecoverimageurl = (ImageView) view.findViewById(R.id.image_cover_image_url);
        }
    }
}
